import {
  Controller,
  Get,
  Post,
  Body,
  // Patch,
  Put,
  Param,
  Delete,
  Query,
  ParseUUIDPipe,
} from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  // 创建
  @Post()
  create(@Body() createUserDto: CreateUserDto) {
    return this.userService.create(createUserDto);
  }

  // 查询所有
  @Get()
  findAll(
    @Query() query: { keyword: string; pageSize: number; pageNum: number },
  ) {
    return this.userService.findAll(query);
  }

  // 查询单个
  @Get(':name')
  findOne(@Param('name') name: string) {
    return this.userService.findOne(name);
  }

  // 修改单个
  @Put(':id')
  update(
    @Param('id', ParseUUIDPipe) id: string,
    @Body() updateUserDto: UpdateUserDto,
  ) {
    return this.userService.update(id, updateUserDto);
  }

  // 删除
  @Delete(':id')
  remove(@Param('id', ParseUUIDPipe) id: string) {
    return this.userService.remove(id);
  }
}
